package com.glory.brepda.activity.mfg;

import android.widget.LinearLayout;
import android.widget.TextView;
import androidx.recyclerview.widget.RecyclerView;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.glory.brepda.R;
import com.glory.brepda.adapter.GoldenSmapleAdapter;
import com.glory.brepda.adapter.ToolInfoByLotAdapter;
import com.glory.brepda.base.BaseActivity;
import com.glory.brepda.entity.GoldenSampleTestDataEntity;
import com.glory.brepda.entity.LotInfoEntity;
import com.glory.brepda.entity.PageInfoEntity;
import com.glory.brepda.entity.ParametersEntity;
import com.glory.brepda.entity.ToolInfoByLotEntity;
import com.glory.brepda.entity.response.BaseResponseBean;
import com.glory.brepda.utils.LotUtils;
import com.glory.brepda.utils.NetUtils;
import com.google.gson.Gson;
import com.google.gson.JsonObject;
import com.google.gson.JsonParser;
import com.google.gson.reflect.TypeToken;
import com.lzy.okgo.model.Response;
import com.pda.platform.ui.ui_pdaplatform.callback.FreeUI_DialogEntityCallBack;
import com.pda.platform.ui.ui_pdaplatform.callback.FreeUI_EntityCallBack;
import com.pda.platform.ui.ui_pdaplatform.dialog.FreeUI_GeneralPop;
import com.pda.platform.ui.ui_pdaplatform.view.FreeUI_ClearEditText;

import java.util.ArrayList;

import butterknife.BindView;

public class ToolInfoByLotActivity extends BaseActivity {


    @BindView(R.id.tvTitle)
    TextView tvTitle;
    @BindView(R.id.etLot)
    FreeUI_ClearEditText etLot;
    @BindView(R.id.llMain)
    LinearLayout llMain;
    @BindView(R.id.rvToolInfoByLot)
    RecyclerView rvToolInfoByLot;
    @BindView(R.id.tvMainMatType)
    TextView tvMainMatType;
    @BindView(R.id.tvCustomerCode)
    TextView tvCustomerCode;
    @BindView(R.id.tvstep)
    TextView tvstep;
    @BindView(R.id.tvPartName)
    TextView tvPartName;

    private ArrayList<String> testDataList = new ArrayList<>();
    private ToolInfoByLotAdapter ToolInfoByLotAdapter;
    private ArrayList<GoldenSampleTestDataEntity.DataEntity> dataEntities;


    @Override
    protected int getLayoutResId() {
        return R.layout.activity_lot_toolinfo;
    }

    @Override
    protected void initView() {
        tvTitle.setText("治具信息查询");
        setMainLayout(llMain);

        initEdit(etLot, s -> {
            //获取lot信息
            LotUtils.searchLotInfo(ToolInfoByLotActivity.this, s, getSupportFragmentManager(), new LotUtils.netCallback<LotInfoEntity>() {
                @Override
                public void onSuccess(LotInfoEntity response) {
                    tvCustomerCode.setText(response.getLOT().getCUSTOMERCODE());
                    tvMainMatType.setText(response.getLOT().getMAINMATTYPE());
                    tvstep.setText(response.getLOT().getSTEPDESC());
                    tvPartName.setText(response.getLOT().getPARTNAME());
                    getToolInfoList();
                }

                @Override
                public void onFail(Throwable t) {
                    loadError(t, "LOTQUERY");
                }
            });
        });
    }

    private void getToolInfoList(){
        FreeUI_EntityCallBack<BaseResponseBean<ToolInfoByLotEntity>> callBack = new FreeUI_DialogEntityCallBack<BaseResponseBean<ToolInfoByLotEntity>>
                (new TypeToken<BaseResponseBean<ToolInfoByLotEntity>>() {
                }.getType(), getSupportFragmentManager(), this) {

            @Override
            public void onSuccess(Response<BaseResponseBean<ToolInfoByLotEntity>> response) {
                super.onSuccess(response);
                if (response.body().isSuccess(getApplicationContext(), false, getSupportFragmentManager())) {

                    ToolInfoByLotAdapter.setNewData(response.body().getResponse().getBody().getTOOLBOMLINELIST());
                }
            }

            @Override
            public void onError(Response<BaseResponseBean<ToolInfoByLotEntity>> response) {
                super.onError(response);
                loadError(response.getException(),"TOOLBYLOT");
            }
        };
        JsonObject map = new JsonObject();
        map.addProperty("ACTIONTYPE", "QUERYLOTINFO");
        map.addProperty("LOTID", etLot.getText().toString());
        NetUtils.requestPostNet("IF.TOOLBYLOT", "Common", this, map, callBack);
    }

    @Override
    protected void initData() {
        initRecyclerView(rvToolInfoByLot, this);
        ToolInfoByLotAdapter = new ToolInfoByLotAdapter(null,this);
        ToolInfoByLotAdapter.openLoadAnimation(BaseQuickAdapter.ALPHAIN);
        ToolInfoByLotAdapter.isFirstOnly(true);
        rvToolInfoByLot.setAdapter(ToolInfoByLotAdapter);
    }
}
